<?php

namespace Admin\Model;

use Think\Model;

class ProductsModel extends Model {

    protected $trueTableName = 'tb_products';

    public function getFind($where){
        $result = $this->where($where)->find();
        return $result;
    }
    
    public function getList($where,$param){
        $count = $this->where($where)->count();
        $Page = new \Think\Page($count, 10, $param); // 实例化分页类 传入总记录数和每页显示的记录数
        $list = $this->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        return array('list'=>$list,'page'=>$Page->show(),'count'=>$count);
    }
    
    public function saveData($where,$data){
        $result = $this->where($where)->save($data);
        return $result;
    }
    
    public function addData($data){
        $result = $this->add($data);
        return $result;
    }
    
    public function getCateProduct($where){
        $result = $this->alias("a")
                ->join("left join `tb_product_category` as b on a.id=b.productid")
                ->where($where)
                ->field("a.id,a.name,a.cover,price,b.dictid")
                ->select();
        return $result;
    }
}
